package LeetCode;

import Constructs.ListNode;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/5/28.
//
//https://leetcode.cn/problems/remove-duplicates-from-sorted-list/description/
public class 删除链表中的重复元素 {
    public static void main(String[] args) {

    }
    public static ListNode deleteDuplicates(ListNode head) {
        if(head == null || head.next == null)return head;
        ListNode previous = head;
        ListNode next = previous.next;
        while (next != null){
            if(previous.value == next.value){
                previous.next = next.next;
                next = previous.next;
            }else {
                previous = next;
                next = previous.next;
            }
        }
        return head;
    }
}
